<template>
  <el-row class="tab-pane" :gutter="10">
    <el-col class="right-main" :lg="18">
      <p class="where">更多资源>></p>
      <template>
        <el-tabs v-model="activeName">
          <el-tab-pane name="first">
            <span slot="label">
              热门资源
              <img :src="icon1" alt />
            </span>
          </el-tab-pane>
        </el-tabs>
      </template>
      <el-row class="tab-pane">
        <template>
          <el-tabs v-model="name" type="card">
            <el-tab-pane label="电子图书馆" class="first" name="first">
              <el-row class="list" v-if="datas.length!=0">
                <template v-for="(k,index) in datas">
                  <el-col :span="12" class="list-li" :key="index">
                    <el-row>
                      <el-col :span="8" @click.native="link(index)">
                        <img :src="k.cover" alt />
                      </el-col>
                      <el-col :span="14">
                        <p class="name">{{k.title}}</p>
                        <p class="point">
                          <span>点赞：</span>
                          <el-rate v-model="k.rates" disabled show-score text-color="#ff9900"></el-rate>
                        </p>
                        <p class="info">
                          <span>简介:</span>
                          <el-button>{{k.description==''?'暂无简介':k.description}}</el-button>
                        </p>
                        <p class="icon">
                          <el-row>
                            <el-col :span="7" :class="collects.includes(k.file_id)?state:''">
                              <i
                                @click="collectDatas(index)"
                                class="el-icon-star-on"
                                :class="collects.includes(k.file_id)?state:''"
                              ></i>
                              {{collects.includes(k.file_id)?'已收藏':'收藏'}}
                            </el-col>
                            <el-col :span="7">
                              <img :src="liulan" alt />
                              {{k.clicks}}
                            </el-col>
                            <el-col :span="7" @click="pl(index)">
                              <i class="el-icon-chat-dot-round"></i>
                              {{k.comments}}
                            </el-col>
                          </el-row>
                        </p>
                      </el-col>
                    </el-row>
                  </el-col>
                </template>
              </el-row>
              <el-row v-else>
                <el-col>
                  <p style="text-align:center;">暂无数据</p>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="电子音像馆" class="second" name="second" @click="video">
              <el-row class="list" v-if="videoDatas.length!=0">
                <template v-for="(k,index) in videoDatas">
                  <el-col :span="12" class="list-li" :key="index">
                    <el-row>
                      <el-col :span="8" @click.native="link(index)">
                        <img :src="k.cover" alt />
                      </el-col>
                      <el-col :span="14">
                        <p class="name">{{k.title}}</p>
                        <p class="point">
                          格式：
                          <span class="type">{{k.format}}</span>
                        </p>
                        <p class="info">
                          <span>介绍:</span>
                          <el-button>{{k.description==''?'暂无简介':k.description}}</el-button>
                        </p>
                        <p class="icon">
                          <el-row>
                            <el-col :span="7" :class="videoCollects.includes(k.course_id)?state:''">
                              <i
                                @click="collectVideoDatas(index)"
                                class="el-icon-star-on"
                                :class="videoCollects.includes(k.course_id)?state:''"
                              ></i>
                              {{videoCollects.includes(k.course_id)?'已收藏':'收藏'}}
                            </el-col>
                            <el-col :span="6">
                              <img :src="liulan" alt />
                              {{k.clicks}}
                            </el-col>
                            <el-col :span="6" @click="pl(index)">
                              <i class="el-icon-chat-dot-round"></i>
                              {{k.comments}}
                            </el-col>
                            <el-col :span="5">
                              <img :src="down" alt />
                              {{k.comments}}
                            </el-col>
                          </el-row>
                        </p>
                      </el-col>
                    </el-row>
                  </el-col>
                </template>
              </el-row>
              <el-row v-else>
                <el-col>
                  <p style="text-align:center;">暂无数据</p>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </template>
      </el-row>
    </el-col>
    <el-col class="left-aside" :lg="5">
      <div class="news">
        <template>
          <el-tabs v-model="activeName">
            <el-tab-pane label="新闻公告" name="first">
              <template>
                <el-carousel height="240px" direction="vertical" :autoplay="false" :interval="5000">
                  <el-carousel-item v-for="item in 3" :key="item">
                    <ul class="news-list">
                      <li
                        v-for="(item,index) in prizeList"
                        v-bind:key="item.news_id"
                        @click="link(index)"
                      >{{item.news_title}}</li>
                    </ul>
                  </el-carousel-item>
                </el-carousel>
              </template>
            </el-tab-pane>
          </el-tabs>
        </template>
      </div>
      <div class="news">
        <template>
          <el-tabs v-model="activeName">
            <el-tab-pane label="资源统计" name="first">
              <div class="zy1" :style="{ 'background':'url('+ bg1 +') no-repeat 0 0' }">
                <span>电子图书册数</span>
                <span>{{book_total}}</span>
              </div>
              <div class="zy2" :style="{ 'background':'url('+ bg2 +') no-repeat 0 0' }">
                <span>电子音像数量</span>
                <span>{{video_total}}</span>
              </div>
            </el-tab-pane>
          </el-tabs>
        </template>
      </div>
    </el-col>
    <el-col :lg="24" class="content">
      <p class="where">更多资源>></p>
      <template>
        <el-tabs v-model="activeName">
          <el-tab-pane name="first">
            <span slot="label">
              推荐资源
              <img :src="icon2" alt />
            </span>
          </el-tab-pane>
        </el-tabs>
      </template>
      <el-row class="tab-pane">
        <template>
          <el-tabs v-model="type" type="card">
            <el-tab-pane label="电子图书馆" class="first" name="first">
              <el-row class="list">
                <div v-if="recommended.length!=0">
                  <template v-for="(v,index) in recommended">
                    <el-col :span="24" class="list-li" :key="index">
                      <el-row>
                        <el-col :span="3">
                          <img :src="fm1" alt />
                        </el-col>
                        <el-col :span="21">
                          <p class="name">
                            <el-row>
                              <el-col :span="8">{{v.title}}</el-col>
                              <el-col :span="4" :offset="12">
                                <el-button type="primary">在线阅读</el-button>
                              </el-col>
                            </el-row>
                          </p>
                          <p class="point">
                            <span>点赞：</span>
                            <el-rate v-model="v.rates" disabled show-score text-color="#ff9900"></el-rate>
                          </p>
                          <p class="info">
                            <span>简介:</span>
                            <el-button>{{v.description==''?'暂无简介':v.description}}</el-button>
                          </p>
                          <p class="icon">
                            <el-row>
                              <el-col :span="3" :class="collects.includes(v.file_id)?state:''">
                                <i
                                  @click="collectRecommended(index)"
                                  class="el-icon-star-on"
                                  :class="collects.includes(v.file_id)?state:''"
                                ></i>
                                {{collects.includes(v.file_id)?'已收藏':'收藏'}}
                              </el-col>
                              <el-col :span="3">
                                <img :src="liulan" alt />
                                {{v.clicks}}
                              </el-col>
                              <el-col :span="3" @click="pl(index)">
                                <i class="el-icon-chat-dot-round"></i>
                                {{v.comments}}
                              </el-col>
                            </el-row>
                          </p>
                        </el-col>
                      </el-row>
                    </el-col>
                  </template>
                </div>

                <div v-else>
                  <template v-show="datas.length=0">
                    <p style="text-align:center;">暂无数据</p>
                  </template>
                </div>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="电子音像馆" class="second" name="second" @click="video">
              <el-row class="list">
                <div v-if="videoRecommended.length!=0">
                  <template v-for="(v,index) in videoRecommended">
                    <el-col :span="24" class="list-li" :key="index">
                      <el-row>
                        <el-col :span="3">
                          <img :src="fm1" alt />
                        </el-col>
                        <el-col :span="21">
                          <p class="name">
                            <el-row>
                              <el-col :span="8">{{v.title}}</el-col>
                              <el-col :span="4" :offset="12">
                                <el-button type="primary">在线阅读</el-button>
                              </el-col>
                            </el-row>
                          </p>
                          <p class="point">
                            <span>点赞：</span>
                            <el-rate v-model="v.rates" disabled show-score text-color="#ff9900"></el-rate>
                          </p>
                          <p class="info">
                            <span>简介:</span>
                            <el-button>{{v.description==''?'暂无简介':v.description}}</el-button>
                          </p>
                          <p class="icon">
                            <el-row>
                              <el-col :span="3" :class="videoCollects.includes(v.course_id)?state:''">
                                <i
                                  @click="collecVideoRecommended(index)"
                                  class="el-icon-star-on"
                                  :class="videoCollects.includes(v.course_id)?state:''"
                                ></i>
                                {{videoCollects.includes(v.course_id)?'已收藏':'收藏'}}
                              </el-col>
                              <el-col :span="3">
                                <img :src="liulan" alt />
                                {{v.clicks}}
                              </el-col>
                              <el-col :span="3" @click="pl(index)">
                                <i class="el-icon-chat-dot-round"></i>
                                {{v.comments}}
                              </el-col>
                            </el-row>
                          </p>
                        </el-col>
                      </el-row>
                    </el-col>
                  </template>
                </div>

                <div v-else>
                  <template v-show="datas.length=0">
                    <p style="text-align:center;">暂无数据</p>
                  </template>
                </div>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </template>
      </el-row>
    </el-col>
    <el-col class="content" :lg="24">
      <p class="where">更多资源>></p>
      <template>
        <el-tabs v-model="activeName">
          <el-tab-pane name="first">
            <span slot="label">
              最新资源
              <img :src="icon3" alt />
            </span>
          </el-tab-pane>
        </el-tabs>
      </template>
      <el-row class="tab-pane">
        <template>
          <el-tabs v-model="name" type="card">
            <el-tab-pane label="电子图书馆" class="first" name="first">
              <el-row class="list" v-if="latest.length!=0">
                <template v-for="(k,index) in latest">
                  <el-col :span="12" class="list-li" :key="index">
                    <el-row>
                      <el-col :span="8" @click.native="link(index)">
                        <img :src="k.cover" alt />
                      </el-col>
                      <el-col :span="14">
                        <p class="name">{{k.title}}</p>
                        <p class="point">
                          <span>点赞：</span>
                          <el-rate v-model="k.rates" disabled show-score text-color="#ff9900"></el-rate>
                        </p>
                        <p class="info">
                          <span>简介:</span>
                          <el-button>{{k.description==''?'暂无简介':k.description}}</el-button>
                        </p>
                        <p class="icon">
                          <el-row>
                            <el-col :span="7" :class="collects.includes(k.file_id)?state:''">
                              <i
                                @click="collectLatest(index)"
                                class="el-icon-star-on"
                                :class="collects.includes(k.file_id)?state:''"
                              ></i>
                              {{collects.includes(k.file_id)?'已收藏':'收藏'}}
                            </el-col>
                            <el-col :span="7">
                              <img :src="liulan" alt />
                              {{k.clicks}}
                            </el-col>
                            <el-col :span="7" @click="pl(index)">
                              <i class="el-icon-chat-dot-round"></i>
                              {{k.comments}}
                            </el-col>
                          </el-row>
                        </p>
                      </el-col>
                    </el-row>
                  </el-col>
                </template>
              </el-row>
              <el-row v-else>
                <el-col>
                  <p style="text-align:center;">暂无数据</p>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="电子音像馆" class="second" name="second" @click.native="video">
              <el-row class="list" v-if="videoLatest.length!=0">
                <template v-for="(k,index) in videoLatest">
                  <el-col :span="12" class="list-li" :key="index">
                    <el-row>
                      <el-col :span="8" @click.native="link(index)">
                        <img :src="k.cover" alt />
                      </el-col>
                      <el-col :span="14">
                        <p class="name">{{k.title}}</p>
                        <p class="point">
                          格式：
                          <span class="type">{{k.format}}</span>
                        </p>
                        <p class="info">
                          <span>介绍:</span>
                          <el-button>{{k.description==''?'暂无简介':k.description}}</el-button>
                        </p>
                        <p class="icon">
                          <el-row>
                            <el-col :span="7" :class="videoCollects.includes(k.course_id)?state:''">
                              <i
                                @click="collectVideoLatest(index)"
                                class="el-icon-star-on"
                                :class="videoCollects.includes(k.course_id)?state:''"
                              ></i>
                              {{videoCollects.includes(k.course_id)?'已收藏':'收藏'}}
                            </el-col>
                            <el-col :span="6">
                              <img :src="liulan" alt />
                              {{k.clicks}}
                            </el-col>
                            <el-col :span="6" @click="pl(index)">
                              <i class="el-icon-chat-dot-round"></i>
                              {{k.comments}}
                            </el-col>
                            <el-col :span="5">
                              <img :src="down" alt />
                              {{k.comments}}
                            </el-col>
                          </el-row>
                        </p>
                      </el-col>
                    </el-row>
                  </el-col>
                </template>
              </el-row>
              <el-row v-else>
                <el-col>
                  <p style="text-align:center;">暂无数据</p>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </template>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import store from "../../store";
import { getList, clickData, myCenter } from "@/api/index";
import { operation, removeFavorite } from "@/api/page";
import { getToken1 } from "@/utils/auth";
export default {
  name: "cont",
  data() {
    return {
      value: 5,
      fm1: require("@/assets/index/fengmian.png"),
      fm2: require("@/assets/index/fengmian_y.png"),
      collection: require("@/assets/index/collection.png"),
      liulan: require("@/assets/index/liulan.png"),
      pinglun: require("@/assets/index/pinglun.png"),
      bg1: require("@/assets/index/bg_ziyuantongji.png"),
      bg2: require("@/assets/index/bg_yinxiang.png"),
      down: require("@/assets/index/download.png"),
      dw: require("@/assets/index/download.png"),
      icon1: require("@/assets/index/remen.png"),
      icon2: require("@/assets/index/tuijian.png"),
      icon3: require("@/assets/index/new.png"),
      activeName: "first",
      name: "first",
      type: "first",
      token: getToken1,
      list: [],
      prizeList: [],
      datas: [],
      latest: [],
      recommended: [],
      collects:[],
      videoDatas: [],
      videoLatest: [],
      videoRecommended: [],
      videoCollects:[],
      form1: {
        type: 1,
      },
      form2: {
        type: 2,
      },
      book_total: null,
      video_total: null,
      state: "state",
      total: null,
      activeIndex: 0,
      intnum: undefined,
    };
  },
  created() {
    this.fentch();
    this.video();
  },
  methods: {
    fentch() {
      this.listLoading = true;
      let params = this.form1;
      getList(params).then((response) => {
        console.log(response);
        this.datas = response.data.hot;
        this.recommended = response.data.recommended;
        this.latest = response.data.latest;
        this.prizeList = response.data.news;
        this.collects = response.data.collection;
        this.book_total = response.data.book_total;
        this.video_total = response.data.video_total;
        this.listLoading = false;
      });
    },
    // 重新获取数据
    dataList() {
      this.listLoading = true;
      let params = this.form1;
      getList(params).then((response) => {
        this.datas = response.data.hot;
        this.collects = response.data.collection;
        this.book_total = response.data.book_total;
        this.video_total = response.data.video_total;
        this.listLoading = false;
      });
    },
    video() {
      this.listLoading = true;

      let params = this.form2;
      getList(params).then((response) => {
        console.log(response);
        this.videoDatas = response.data.hot;
        this.videoRecommended = response.data.recommended;
        this.videoLatest = response.data.latest;
        this.videoCollects = response.data.collection;
        this.listLoading = false;
      })
    },
    select(index) {
      this.active = index;
    },
    link(index) {
      this.$parent.select(5, 5);
    },
    // 分页
    handleCurrentChange(val) {
      this.form.page = val;
      this.dataList();
    },
    // 验证权限
    role() {
      if (!this.token) {
        this.$confirm("额。。。，您好像没有权限，是否去登录?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$router.push("/login");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "您继续浏览吧",
            });
            return false;
          });
      }
    },
    collectDatas(index) {
      this.role();
      if (this.token) {
        if (this.collects.includes(this.datas[index].file_id)) {
          this.removeFavorites(index,this.datas[index].file_id);
        } else {
          this.operations(index,this.datas[index].file_id);
        }
      }
    },
     collectVideoDatas(index) {
      this.role();
      if (this.token) {
        if (this.videoCollects.includes(this.videoDatas[index].course_id)) {
          this.removeFavorites1(index,this.videoDatas[index].course_id);
        } else {
          this.operations1(index,this.videoDatas[index].course_id);
        }
      }
    },
     collectRecommended(index) {
      this.role();
      if (this.token) {
        if (this.collects.includes(this.recommended[index].file_id)) {
          this.removeFavorites(index,this.recommended[index].file_id);
        } else {
          this.operations(index,this.recommended[index].file_id);
        }
      }
    },
     collectVideoRecommended(index) {
      this.role();
      console.log(this.collects);
      if (this.token) {
        if (this.videoCollects.includes(this.videoRecommended[index].course_id)) {
          this.removeFavorites1(index,this.videoRecommended[index].course_idfile_id);
        } else {
          this.operations1(index,this.videoRecommended[index].course_id);
        }
      }
    },
     collectLatest(index) {
      this.role();
      console.log(this.collects);
      if (this.token) {
        if (this.collects.includes(this.latest[index].file_id)) {
          this.removeFavorites(index,this.latest[index].file_id);
        } else {
          this.operations(index,this.latest[index].file_id);
        }
      }
    },
     collectVideoLatest(index) {
      this.role();
      if (this.token) {
        if (this.videoCollects.includes(this.videoLatest[index].course_id)) {
          this.removeFavorites1(index,this.videoLatest[index].course_id);
        } else {
          this.operations1(index,this.videoLatest[index].course_id);
        }
      }
    },
    // 取消收藏
    removeFavorites(index,data) {
      let params = {
        id: data,
        type: 1,
      };
      removeFavorite(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "取消成功",
          });
          this.fentch();
          this.video();
        }
      });
    },
    //收藏
    operations(index,data) {
      let params = {
        id:data,
        type: 1,
        classify: 1,
      }
      operation(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "收藏成功",
          });
               this.fentch();
          this.video();
        }
      })
    },
      // 取消收藏
    removeFavorites1(index,data) {
      let params = {
        id: data,
        type: 2,
      };
      removeFavorite(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "取消成功",
          });
               this.fentch();
          this.video();
        }
      });
    },
    //收藏
    operations1(index,data) {
      let params = {
        id: data,
        type: 2,
        classify: 1,
      }
      operation(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "收藏成功",
          });
               this.fentch();
          this.video();
        }
      })
    }
  },
};
</script>
<style lang="scss" scoped>
.right-main {
  position: relative;
}
.content {
  position: relative;
}
.where {
  position: absolute;
  right: 0;
  top: 0;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(142, 142, 142, 1);
}
.first {
  .point {
    span {
      float: left;
    }
  }
}
.info {
  position: relative;
  > span {
    position: absolute;
    left: 0;
    top: 10px;
  }
}
.first {
  .info {
    position: relative;
    > span {
      position: absolute;
      left: 0;
      top: 6px;
    }
  }
}
.type {
  color: #ff9600;
}
.name {
  font-size: 24px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(22, 22, 22, 1);
  margin-top: 0;
}
.icon {
  padding-top: 40px;
}
.list {
  padding-top: 30px;
  img {
    margin-left: 0;
  }
  > .el-col-12 {
    width: 48%;
  }
  > .el-col-12:nth-child(odd) {
    margin-right: 4%;
  }
  .el-col-16 {
    padding-left: 20px;
  }
  .el-col-8 {
    img {
      width: 90%;
    }
  }
}
.list-li {
  padding-bottom: 30px;
  cursor: pointer;
  > .el-row {
    border: 1px solid #ddd;
    padding: 20px;
  }
}
.icon {
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(142, 142, 142, 1);
  img {
    margin-right: 10px;
  }
}
.el-carousel__container {
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(220, 220, 220, 1);
  box-shadow: 1px 2px 10px 0px rgba(153, 153, 153, 0.23);
  border-radius: 10px;
  padding: 20px;
}

.news-list {
  li {
    position: relative;
    text-indent: 20px;
    color: #505050;
    padding: 8px 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  li::after {
    display: inline-block;
    content: "";
    position: absolute;
    left: 20px;
    top: 15px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(142, 142, 142, 1);
  }
  li:hover {
    color: #ff8a00 !important;
  }
  li:hover::after {
    background: #ff8a00 !important;
  }
}
.left-aside {
  padding-left: 30px !important;
}
</style>
<style lang="scss">
ul,
li {
  padding: 0;
  list-style: none;
}
.tab-pane .el-tabs__item {
  font-size: 20px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(80, 80, 80, 1);
  line-height: 50px !important;
}
.tab-pane .el-tabs__item.is-active {
  color: #1ca2a8;
  img {
    margin-left: 20px;
    margin-bottom: -2px;
  }
}
.tab-pane .el-tabs__active-bar {
  background-color: #1ca2a8;
  width: 80px !important;
}
.tab-pane .el-tabs__item {
  height: 50px;
  line-height: normal;
}
.tab-pane .el-tabs__header {
  margin: 0;
}
.info .el-button {
  border: none;
  padding: 0;
  width: 100%;
  line-height: 30px;
  white-space: normal;
  text-align: left;
  text-indent: 45px;
  span {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 20px;
    color: #4f4f4f;
  }
}
.info {
  .el-button:hover {
    background: none;
  }
}
.tab-pane .el-tabs--card > .el-tabs__header .el-tabs__nav {
  float: right;
}
.el-carousel__container {
  margin-top: 30px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(220, 220, 220, 1);
  box-shadow: 1px 2px 10px 0px rgba(153, 153, 153, 0.23);
  border-radius: 10px;
  overflow: hidden;
}
.zy1,
.zy2 {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 120px;
  text-align: center;
  margin-top: 20px;
  background-size: 100% !important;
  span {
    margin: 0 10px;
  }
  span:first-child {
    font-size: 21px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
  }
  span:last-child {
    font-size: 41px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-style: italic;
    color: rgba(255, 255, 255, 1);
  }
}
.tab-pane .el-tabs--card > .el-tabs__header {
  border-bottom: none;
}
.tab-pane .el-tabs--card > .el-tabs__header .el-tabs__item {
  border-color: #e4e7ed;
}
.tab-pane .el-tabs--card > .el-tabs__header .el-tabs__item.is-active {
  border-bottom: none;
}
.state {
  color: #1ca2a7;
}
.name {
  .el-button {
    width: 130px;
    height: 42px;
    background: rgba(28, 162, 167, 1);
    border-radius: 4px;
    font-size: 20px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
  }
}
</style>